﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using System.IO;
using System.Threading;
using System.Globalization;
using System.Resources;
using DataAccess.BusinessObject;

namespace EnmineKaitlin
{
    public class Global : System.Web.HttpApplication
    {

        protected void Application_Start(object sender, EventArgs e)
        {
            DataAccess.Common.CDBase.strConnectionString = ConfigurationManager.ConnectionStrings["connectsql"].ConnectionString;
            Application["useronline"] = 0;
            Common.PageBase.domain = ConfigurationManager.AppSettings["domain"];
        }

        protected void Session_Start(object sender, EventArgs e)
        {
            try
            {
                //Tổng số lượt truy cập                
                BCountVisit _BCountVisit = new BCountVisit();
                int count_visit = _BCountVisit.get();
                if (count_visit>0)
                {                    
                    //Tang luot truy cap
                    count_visit++;
                    // khóa website
                    Application.Lock();
                    // gán biến Application count_visit
                    Application["count_visit"] = count_visit;
                    // Mở khóa website
                    Application.UnLock();
                    //Luu count visit
                    _BCountVisit.update();
                }
                // Ngược lại thì
                else
                {                    
                    Application.Lock();
                    // gán biến Application count_visit
                    Application["count_visit"] = 1;
                    // Mở khóa website
                    Application.UnLock();                 
                }
            }
            catch (Exception ex)
            {
                Application["count_visit"] = 1;
            }
            //Số người online
            Application.Lock();
            Application["useronline"] = int.Parse(Application["useronline"].ToString()) + 1;
            Application.UnLock();
            //Khởi tạo sesion language
            Session["LangID"] = "vi-VN";
            //Gán globlization mặc định
            Thread.CurrentThread.CurrentCulture = new CultureInfo(Session["LangID"].ToString());
            Common.PageBase.rm = new ResourceManager("Resources.Language", System.Reflection.Assembly.Load("App_GlobalResources"));
            Common.PageBase.ci = Thread.CurrentThread.CurrentCulture;
            //Khởi tạo sesion user
            Session["username"] = "";
            Session["permission"] = "";
            Session["fullname"] = "";
        }

        protected void Application_BeginRequest(object sender, EventArgs e)
        {
            
        }

        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {

        }

        protected void Application_Error(object sender, EventArgs e)
        {

        }

        protected void Session_End(object sender, EventArgs e)
        {

        }

        protected void Application_End(object sender, EventArgs e)
        {

        }
    }
}